﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace skvote
{
    public partial class admin_question_add : System.Web.UI.Page
    {
        private OleDbConnection connection = new conn().CreateConnection();
        protected void Page_Load(object sender, EventArgs e)
        {
            function.check();
        }

        protected void submit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request["tid"]))
            {
                function.showErr("请先选择投票问题",Response,Request);
                return;
            }
            if (string.IsNullOrEmpty(Request["question"]))
            {
                function.showErr("答案不能为空",Response,Request);
            }
            function.IsNumberOrEmpty(Request["ps"]);
            try
            {
                connection.Close();
                connection.Open();
                OleDbCommand cmd = new OleDbCommand("select sid from xh_title where id="+Request["tid"],connection);
                OleDbDataReader dr = cmd.ExecuteReader();
                string sid = "";
                while (dr.Read())
                {
                    sid = dr["sid"].ToString().Trim();
                }
                dr.Close();
                cmd.CommandText = "insert into xh_question(tid,sid,question,ps) values(" + Request["tid"].Trim() + "," + sid.Trim() + ",\"" + Request["question"].Trim() + "\"," + Request["ps"].Trim() + ")";
                cmd.ExecuteNonQuery();
                cmd.CommandText = "select sum(ps) as ps from xh_question where tid=" + Request["tid"].Trim();
                string vcount = cmd.ExecuteScalar().ToString();
                cmd.CommandText = "update xh_title set vcount=" + vcount + " where id=" + Request["tid"].Trim();
                cmd.ExecuteNonQuery();                
            }
            finally
            {
                connection.Close();
            }
            function.successMsg("添加投票答案成功");
        }
    }
}
